﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;

namespace StockCrawler
{
    public static class CrawlingUtility
    {
        public static DateTime ParseDate(string input)
        {
            return DateTime.ParseExact(input.Trim(), "dd/MM/yyyy", null);
        }

        public static decimal ParsePrice(string input)
        {
            try
            {
                return Convert.ToDecimal(input.Trim());
            }
            catch
            {
                return 0;
            }
        }

        public static long ParseVolume(string input)
        {
            try
            {                
                return Int64.Parse(input.Trim(), NumberStyles.AllowThousands | NumberStyles.AllowLeadingSign);
            }
            catch(Exception ex)
            {
                return 0;
            }
        }

        public static decimal ParseNumber(string input)
        {
            try
            {
                return Convert.ToDecimal(input.Trim());
            }
            catch
            {
                return 0;
            }
        }
    }
}
